#include <stdio.h>
#include <stdlib.h>

struct IntHolder
{
    explicit IntHolder(int *val = 0) : val_(val) {}
    ~IntHolder()
    {
        printf("Value: %d\n", *val_); // Bom!
    }
    void set(int *val) { val_ = val; }
    int *get() { return val_; }

    int *val_;
};

void test()
{
    // x,holder 生命周期一致, 不会触发
    IntHolder holder;
    int x = 2;
    holder.set(&x);
}

int main(int argc, char *argv[])
{
    test();

    return 0;
}